%Script to show histogram

cateName = cell(10);
cateName{1} = 'White';
cateName{2} = 'Black';
cateName{3} = 'Red';
cateName{4} = 'Yellow';
cateName{5} = 'Dark Blue';
cateName{6} = 'Green';
cateName{7} = 'Gray';
cateName{8} = 'Silver';
cateName{9} = 'Light Blue';
cateName{10}= 'Champion';


mkdir('./removeColor');
dataPath = '../CarColorSamples';
labelVec=[];
load('model2.mat');
gmm=model;
for iColor = 0:9
    dataCell = cell(0);
    iSample= 1;
    color_path = fullfile(dataPath, num2str(iColor));
    fileList = dir(fullfile(color_path,'*.jpg'));
    for iFile= 1:length(fileList);
      img=imresize(imread(fullfile(color_path,fileList(iFile).name)),[NaN,200]);
      vecImg = reshape(im2double(img),[],3);
      distMat = mahal(gmm,vecImg); 
      ind1 = find(distMat(:,2)<1);
      ind2 = find(distMat(:,5)<1);
      idx = sort(unique([ind1;ind2])); 
      vecImg(idx,1)=1;
      vecImg(idx,2)=0;
      vecImg(idx,3)=0;
      imwrite(reshape(vecImg,size(img)),['./removeColor/',cateName{iColor+1} '_' num2str(iFile,'%04d') '.jpg']);
    end
   disp(cateName{iColor+1});
end
